package com.sunnada.nginx.controller;

import com.sunnada.nginx.exception.CustonException;
import com.sunnada.nginx.service.StatusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "nginx控制", description = "nginx控制")
@RestController
@RequestMapping("status")
public class StatusController {

    @Autowired
    StatusService statusService;

    /**
     * 获得Nginx状态
     * @return
     */
    @ApiOperation(value="查看nginx状态", notes="查看nginx状态",httpMethod = "GET")
    @GetMapping
    @ResponseBody
    public String nginxStatus(){
        return statusService.isStart()?"start":"stop";
    }

    /**
     * 设置Nginx状态
     * @return
     */
    @ApiOperation(value="nginx状态切换", notes="nginx状态切换",httpMethod = "PUT")
    @PutMapping
    @ResponseBody
    public String setNginxStatus() throws CustonException {
        if (statusService.isStart()){
            statusService.stop();
        }else {
            statusService.start();
        }
        return "success";
    }
}
